//
//  BHUserPageDataModel.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/8/10.
//

import UIKit

class BHUserPageDataModel: NSObject {
    var userId: String = ""
    var name: String = ""
    var avatar: String = ""
    var companyName: String = "" // 公司名称
    var occupation: String = "" // 职业
    
    var sex: Int = 0  // 0-未知,1-男,2-女
    
    // 看他人主页的时候
    var attentionFlag: Int = 0
    
    
    var sexName: String  {
        get {
            if sex == 1 {
                return "男"
            }else if sex == 2 {
                return "女"
            }else {
                return "未知"
            }
        }
    }
    
    // 记录数据
    var attentionNum: Int = 0 // 我的/他的关注个数
    var fansNum: Int = 0 // 关注我的/他的(我的粉丝)
    var myLike: Int = 0  // 我的点赞(圈子)
    var totalNum: Int = 0  // 我的/他的获赞与收藏   个人主页展示使用 不可点击跳转
    
    
    func parseDic(_ dic: [String:Any]) {
        self.userId = BHJsonTool.decodeStringFromDic(dic: dic, key: "id")
        self.name = BHJsonTool.decodeStringFromDic(dic: dic, key: "name")
        self.avatar = BHJsonTool.decodeStringFromDic(dic: dic, key: "avatar")
        self.companyName = BHJsonTool.decodeStringFromDic(dic: dic, key: "companyName")
        self.occupation = BHJsonTool.decodeStringFromDic(dic: dic, key: "occupation")

        self.sex = BHJsonTool.decodeIntFromDic(dic: dic, key: "sex")
        self.attentionFlag = BHJsonTool.decodeIntFromDic(dic: dic, key: "attentionFlag")
        
    }
    
    func parseNum(dic: [String: Any]) {
        self.attentionNum = BHJsonTool.decodeIntFromDic(dic: dic, key: "attentionNum")
        self.fansNum = BHJsonTool.decodeIntFromDic(dic: dic, key: "fansNum")
        self.myLike = BHJsonTool.decodeIntFromDic(dic: dic, key: "myLike")
        self.totalNum = BHJsonTool.decodeIntFromDic(dic: dic, key: "totalNum")
    }
    
    
    func loadFromGloab()  {
        let model = BHMeUserInfoModel.shared
        
        self.userId = model.userId
        self.name = model.username
        self.avatar = model.avatar
        self.companyName = model.companyName
        self.occupation = model.occupation
        self.sex = model.sex
        
        self.attentionNum = model.attentionNum
        self.fansNum = model.fansNum
        self.myLike = model.myLike
        self.totalNum = model.totalNum
    }
}
